import 'dart:async';

import 'package:flutter/material.dart';
import 'package:flutter_admin/pages/large_screen/product_quant/main.dart';
import 'package:flutter_admin/pages/large_screen/product_workreportrecord/main.dart';
import 'package:flutter_admin/pages/large_screen/production_issue/main.dart';
import 'package:flutter_admin/pages/large_screen/production_monitoring.dart';
import 'package:flutter_admin/pages/large_screen/workshop_screen/main.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';

import 'location_screen/main.dart';
import 'logistics_operation_table.dart';
import 'production_schedule/main.dart';

class KanbanManagement extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    // TODO: implement build
    Widget buildGrid() {
      return new GridView.extent(
        maxCrossAxisExtent: 800.0,
        padding: const EdgeInsets.all(4.0),
        mainAxisSpacing: 2.0,
        crossAxisSpacing: 2.0,
        children: [
          new Container(
            color: new Color.fromRGBO(0, 0, 0, 1.0),
            child: RaisedButton(
              child: new Text('1(已完成)'),
              onPressed: () {
                Navigator.push(
                    context,
                    new MaterialPageRoute(
                        builder: (context) => new ProductQuant()));
              },
            ),
          ),
          new Container(
            color: new Color.fromRGBO(0, 0, 0, 1.0),
            child: RaisedButton(
              child: new Text('2（待调整样式）'),
              onPressed: () {
                Navigator.push(
                    context,
                    new MaterialPageRoute(
                        builder: (context) => new ProductionIssue()));
              },
            ),
          ),
          new Container(
            color: new Color.fromRGBO(0, 0, 0, 1.0),
            child: RaisedButton(
              child: new Text('3（已完成）'),
              onPressed: () {
                Navigator.push(
                    context,
                    new MaterialPageRoute(
                        builder: (context) =>
                            new ProductWorkreportrecordScreen()));
              },
            ),
          ),
          new Container(
            color: new Color.fromRGBO(0, 0, 0, 1.0),
            child: RaisedButton(
              child: new Text('4（等李灼）'),
              onPressed: () {
                Navigator.push(
                    context,
                    new MaterialPageRoute(
                        builder: (context) => new ProductionMonitoring()));
              },
            ),
          ),
          new Container(
            color: new Color.fromRGBO(0, 0, 0, 1.0),
            child: RaisedButton(
              child: new Text('5'),
              onPressed: () {
                Navigator.push(
                    context,
                    new MaterialPageRoute(
                        builder: (context) => new ProductionSchedule()));
              },
            ),
          ),
          new Container(
            color: new Color.fromRGBO(0, 0, 0, 1.0),
            child: RaisedButton(
              child: new Text('6（待调整样式）'),
              onPressed: () {
                Navigator.push(
                    context,
                    new MaterialPageRoute(
                        builder: (context) => new BulletinBoard()));
              },
            ),
          ),

          new Container(
            color: new Color.fromRGBO(0, 0, 0, 1.0),
            child: RaisedButton(
              child: new Text('7'),
              onPressed: (){
                Navigator.push(
                    context,
                    new MaterialPageRoute(builder: (context) => new WorkshopScreen())
                );
              },
            ),),

          new Container(
            color: new Color.fromRGBO(0, 0, 0, 1.0),
            child: RaisedButton(
              child: new Text('8'),
              onPressed: (){
                Navigator.push(
                    context,
                    new MaterialPageRoute(builder: (context) => new LocationScreen())
                );
              },
            ),),
          // new Container(
          //   color: new Color.fromRGBO(0, 0, 0, 1.0),
          //   child: RaisedButton(
          //     child: new Text('6'),
          //     onPressed: (){
          //       Navigator.push(
          //           context,
          //           new MaterialPageRoute(builder: (context) => new ProductionDesign(key: key))
          //       );
          //     },
          //   ),),
          // new Container(
          //   color: new Color.fromRGBO(0, 0, 0, 1.0),
          //   child: RaisedButton(
          //     child: new Text('7'),
          //     onPressed: (){
          //       Navigator.push(
          //           context,
          //           new MaterialPageRoute(builder: (context) => new AchievementRate())
          //       );
          //     },
          //   ),),
          // new Container(
          //   color: new Color.fromRGBO(0, 0, 0, 1.0),
          //   child: RaisedButton(
          //     child: new Text('8'),
          //     onPressed: (){
          //       Navigator.push(
          //           context,
          //           new MaterialPageRoute(builder: (context) => new DeviceRunning(key: key))
          //       );
          //     },
          //   ),),
          // new Container(
          //   color: new Color.fromRGBO(0, 0, 0, 1.0),
          //   child: RaisedButton(
          //     child: new Text('9'),
          //     onPressed: (){
          //       Navigator.push(
          //           context,
          //           new MaterialPageRoute(builder: (context) => new Oven(key: key))
          //       );
          //     },
          //   ),),
          // new Container(
          //   color: new Color.fromRGBO(0, 0, 0, 1.0),
          //   child: RaisedButton(
          //     child: new Text('10'),
          //     onPressed: (){
          //       Navigator.push(
          //           context,
          //           new MaterialPageRoute(builder: (context) => new OEEScreen())
          //       );
          //     },
          //   ),),
          // new Container(
          //   color: new Color.fromRGBO(0, 0, 0, 1.0),
          //   child: RaisedButton(
          //     child: new Text('11'),
          //     onPressed: (){
          //       Navigator.push(
          //           context,
          //           new MaterialPageRoute(builder: (context) => new OEEBoard())
          //       );
          //     },
          //   ),),
          // new Container(
          //   color: new Color.fromRGBO(0, 0, 0, 1.0),
          //   child: RaisedButton(
          //     child: new Text('12'),
          //     onPressed: (){
          //       Navigator.push(
          //           context,
          //           new MaterialPageRoute(builder: (context) => new QualityKanban())
          //       );
          //     },
          //   ),),
          // new Container(
          //   color: new Color.fromRGBO(0, 0, 0, 1.0),
          //   child: RaisedButton(
          //     child: new Text('13'),
          //     onPressed: (){
          //       Navigator.push(
          //           context,
          //           new MaterialPageRoute(builder: (context) => new PassRateScreen())
          //       );
          //     },
          //   ),),
          // new Container(
          //   color: new Color.fromRGBO(0, 0, 0, 1.0),
          //   child: RaisedButton(
          //     child: new Text('14'),
          //     onPressed: (){
          //       Navigator.push(
          //           context,
          //           new MaterialPageRoute(builder: (context) => new ControlBoard())
          //       );
          //     },
          //   ),),
          // new Container(
          //   color: new Color.fromRGBO(0, 0, 0, 1.0),
          //   child: RaisedButton(
          //     child: new Text('15'),
          //     onPressed: (){
          //       Navigator.push(
          //           context,
          //           new MaterialPageRoute(builder: (context) => new SPCScreen())
          //       );
          //     },
          //   ),),
          // new Container(
          //   color: new Color.fromRGBO(0, 0, 0, 1.0),
          //   child: RaisedButton(
          //     child: new Text('16'),
          //     onPressed: (){
          //       Navigator.push(
          //           context,
          //           new MaterialPageRoute(builder: (context) => new ExceScreen())
          //       );
          //     },
          //   ),),
          // new Container(
          //   color: new Color.fromRGBO(0, 0, 0, 1.0),
          //   child: RaisedButton(
          //     child: new Text('17'),
          //     onPressed: (){
          //       Navigator.push(
          //           context,
          //           new MaterialPageRoute(builder: (context) => new ExceScreen())
          //       );
          //     },
          //   ),),
          // new Container(
          //   color: new Color.fromRGBO(0, 0, 0, 1.0),
          //   child: RaisedButton(
          //     child: new Text('18'),
          //     onPressed: (){
          //       Navigator.push(
          //           context,
          //           new MaterialPageRoute(builder: (context) => new LogisticsOperation())
          //       );
          //     },
          //   ),),
        ],
      );
    }

    return new Center(
      child: buildGrid(),
    );
  }
}

class CarouselEffect extends StatefulWidget {
  bool? isFullScreen;

  CarouselEffect({Key? key, this.isFullScreen = false}) : super(key: key);

  @override
  _CarouselEffectState createState() => _CarouselEffectState();
}

class _CarouselEffectState extends State<CarouselEffect> {
  Duration duration = Duration(seconds: 60);

  PageController _pageController = PageController(initialPage: 0);

  late Timer _timer;

  late int _totalPages;

  late int _currentPage;

  @override
  void initState() {
    _currentPage = 0;
    _totalPages = 2;
    super.initState();

    _timer = Timer.periodic(duration, (timer) {
      _currentPage = (_currentPage + 1) % _totalPages;
      // _pageController.jumpToPage(_currentPage);
      _pageController.animateToPage(_currentPage,
          duration: new Duration(milliseconds: 500),
          curve: new ElasticOutCurve(4));
    });
  }

  @override
  void dispose() {
    _timer.cancel();
    super.dispose();
  }

  @override
  Widget build(BuildContext context) {
    return Stack(
      children: [
        PageView(
          scrollDirection: Axis.horizontal,
          controller: _pageController,
          allowImplicitScrolling: true,
          children: [
            // ProductQuant(),
            // ProductionIssue(),
            // ProductWorkreportrecordScreen(),
            // ProductionMonitoring(),
            // ProductionSchedule(),
            // BulletinBoard(),
            WorkshopScreen(),
            LocationScreen(),
          ],
        ),
        Positioned(
          bottom: 25.h,
          right: 25.h,
          child: widget.isFullScreen!
              ? IconButton(
                  icon: Icon(Icons.fullscreen_exit),
                  color: Colors.white,
                  onPressed: () => {Navigator.pop(context, true)},
                )
              : IconButton(
                  icon: Icon(Icons.fullscreen),
                  color: Colors.white,
                  onPressed: () {
                    _timer.cancel();
                    Navigator.push(
                        context,
                        new MaterialPageRoute(
                            builder: (context) => new CarouselEffect(
                                  isFullScreen: true,
                                ))).then((value) {
                      _timer = Timer.periodic(duration, (timer) {
                        _currentPage = (_currentPage + 1) % _totalPages;
                        _pageController.jumpToPage(_currentPage);
                      });
                    });
                  },
                ),
        )
      ],
    );
  }
}
